/**
 * @author LKQ
 * @date 2022/2/28 15:46
 * @description 反序中序遍历
 */
public class Solution {
    public static void main(String[] args) {
        TreeNode t0 = new TreeNode(0), t3 = new TreeNode(3), t5 = new TreeNode(5),  t8 = new TreeNode(8),
                t2 = new TreeNode(2, null, t3), t7 = new TreeNode(7, null, t8),
                t6 = new TreeNode(6, t5, t7), t1 = new TreeNode(1, t0, t2), t4 = new TreeNode(4, t1, t6);
        Solution solution = new Solution();
        solution.bstToGst(t4);

    }
    int sum = 0;
    public TreeNode bstToGst(TreeNode root) {
        if (root != null) {
            bstToGst(root.right);
            sum += root.val;
            root.val = sum;
            bstToGst(root.left);
        }
        return root;
    }

}